package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.mes.vo.product.ProOrderVo;
import com.ruoyi.mes.vo.product.ProOutHouVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProOrder;
import com.ruoyi.mes.service.IProOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品订单Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "产品订单")
@RestController
@RequestMapping("/mes/proorder")
public class ProOrderController extends BaseController
{
    @Autowired
    private IProOrderService proOrderService;

    /**
     * 查询产品订单列表
     */
    @ApiOperation(value = "查询产品订单列表")
    @PreAuthorize("@ss.hasPermi('mes:proorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProOrder proOrder)
    {
        startPage();
        List<ProOrder> list = proOrderService.selectProOrderList(proOrder);
        return getDataTable(list);
    }

    /**
     * 导出产品订单列表
     */
    @ApiOperation(value = "导出产品订单列表")
    @PreAuthorize("@ss.hasPermi('mes:proorder:export')")
    @Log(title = "产品订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProOrder proOrder)
    {
        List<ProOrder> list = proOrderService.selectProOrderList(proOrder);
        ExcelUtil<ProOrder> util = new ExcelUtil<ProOrder>(ProOrder.class);
        util.exportExcel(response, list, "产品订单数据");
    }

    /**
     * 获取产品订单详细信息
     */
    @ApiOperation(value = "获取产品订单详细信息")
    @PreAuthorize("@ss.hasPermi('mes:proorder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(proOrderService.selectProOrderById(id));
    }

    /**
     * 新增产品订单
     */
    @PreAuthorize("@ss.hasPermi('mes:proorder:add')")
    @Log(title = "产品订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProOrder proOrder)
    {
        return toAjax(proOrderService.insertProOrder(proOrder));
    }

    /**
     * 修改产品订单
     */
    @ApiOperation(value = "修改产品订单")
    @PreAuthorize("@ss.hasPermi('mes:proorder:edit')")
    @Log(title = "产品订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProOrder proOrder)
    {
        return toAjax(proOrderService.updateProOrder(proOrder));
    }

    /**
     * 删除产品订单
     */
    @ApiOperation(value = "删除产品订单")
    @PreAuthorize("@ss.hasPermi('mes:proorder:remove')")
    @Log(title = "产品订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proOrderService.deleteProOrderByIds(ids));
    }

    //**************************************************************
    /**
     * 增 - 产品订单
     * @param proOrderVo
     * @return
     */
    @PostMapping("/saveOrder")
    public AjaxResult saveOrder(@RequestBody ProOrderVo proOrderVo){
        return proOrderService.saveOrder(proOrderVo);
    }

    /**
     * 删 - 产品订单 - id
     * @param orderId
     * @return
     */
    @DeleteMapping("/deleteByOrderId")
    public AjaxResult deleteByOrderId(@RequestParam Long orderId){
        return proOrderService.deleteByOrderId(orderId);
    }


    /**
     * 改 - 产品订单
     * @param proOrderVo
     * @return
     */
    @PutMapping("/editProOrder")
    public AjaxResult editProOrder (@RequestBody ProOrderVo proOrderVo){
        return proOrderService.editProOrder(proOrderVo);
    }

    /**
     * 查 - 产品订单详情 - id
     * @param orderId
     * @return
     */
    @GetMapping("/getDetails")
    public AjaxResult getDetails(@RequestParam Long orderId){
        return proOrderService.getDetails(orderId);
    }

    /**
     * 查 - 产品订单分页 - 不重复订单编码
     * @param proOrder
     * @return
     */
    @GetMapping("/orderList")
    public TableDataInfo orderList(ProOrder proOrder){
        startPage();
        List<ProOrder> list = proOrderService.selectDistinctOrders(proOrder);
        return getDataTable(list);
    }

    /**
     * 产品出库
     * @param proOutHouVo
     * @return
     */
    @PostMapping("/proOuthou")
    public AjaxResult proOuthou(@RequestBody ProOutHouVo proOutHouVo){
        return proOrderService.proOuthou(proOutHouVo);
    }

    /**
     * 查 - 订单出库信息
     * @param orderNumber 订单编号
     * @return
     */
    @GetMapping("/getOutHouInfo")
    public AjaxResult getOutHouInfo(@RequestParam String orderNumber){
        return proOrderService.getOutHouInfo(orderNumber);
    }

}
